1. Technical Field
This invention relates to the field of computer graphics, and in particular to methods for implementing shading in computer graphics.
2. Background Art
Computer images having realistic three dimensional appearances (xe2x80x9c3D imagesxe2x80x9d) are becoming increasingly prevalent in games, multi-media, and other graphics-heavy software. The methods employed to generate 3D images require processing power that has only recently become available in personal computers. A standard method for generating a 3D image begins with sets of polygons that represent the surfaces of each object in the image. An object that has a moderately complex shape may require thousands of polygons to represent its surface, and an image that includes multiple objects may require tens or even hundreds of thousands of polygons. Illumination and orientation data for each of these polygons must be processed and converted to pixel level data to generate a 3D image on a computer monitor. A computer may have to process 50 million pixels (≈0.5 million polygons) per second to generate a 3D image that includes multiple objects of moderate complexity. This places a significant burden on the processing power of the computer.
Image processing is implemented by a 3D pipeline that typically includes a geometry stage and a rendering stage. In the geometry stage, the orientation of each polygon and the location of any light sources that illuminate the polygon are determined with respect to a reference coordinate system and specified by vectors associated with the polygon""s vertices. This vertex data is transformed to a coordinate system (xe2x80x9ccamera coordinate systemxe2x80x9d) that facilitates viewing the image on a computer monitor and rotated to a desired orientation. In the rendering stage, the vertex data for each polygon is converted into the pixel level data necessary to represent the object on the computer monitor. Since there are tens to hundreds of pixels per polygon, rendering significantly slows the image generation process.
The two dimensional (2D) image on the computer monitor obtains its 3D appearance through lighting and perspective effects implemented by the graphics pipeline. The 3D appearance of an object depends significantly on the shading method used to assign color values to the pixels of the polygons. Realistic 3D images require relatively sophisticated shading methods that determine color values on a pixel by pixel basis. Consequently, these shading methods are implemented during the rendering stage of the pipeline.
The principal shading methods are, in order of increasing sophistication, flat shading, Gouraud shading, and Phong shading. Flat shading assigns the same color values to all the pixels in a polygon. Gouraud shading assigns color values to the pixels by interpolating from the color values at the vertices of the polygon. Phong shading assigns color values by interpolating a normal vector for each pixel from the normal vectors at the polygon vertices, and evaluating an illumination equation at each pixel using its interpolated normal vector. Phong shading and its variants are referred to as per-pixel shading methods, since the colors of an image are calculated for each pixel according to its orientation characteristics. These per pixel orientation characteristics are also necessary to implement advanced graphic features, such as bump mapping. Bump mapping modifies lighting features by perturbing the surface normal from its interpolated value and determining color values using the perturbed normal.
Systems that generate fast, interactive graphics typically employ flat and Gouraud shading. These methods employ approximations in the rendering stage that are relatively cheap computationally, and the corresponding images can be generated in real time without elaborate graphics hardware. The images produced by these methods lack the lighting effects that distinguish quality 3D images, such as realistic specular highlights and diffuse light scattering. In addition, these methods are not amenable to bump mapping, since per pixel normal orientations are never determined. High end computer systems may include advanced rendering hardware to implement Phong shading. Even with high quality graphics hardware, the computational cost of Phong shading makes it difficult to generate real-time, interactive 3D images.
There is thus the need for a practical implementation of per-pixel shading methods that are suitable for use in real-time, interactive 3D graphics applications and may be implemented without the need for sophisticated graphics hardware.
The present invention provides per-pixel shading that is fast enough for real time interactive graphics applications and may be implemented using standard graphics hardware.
In accordance with the present invention, color values are precalculated, collected in a color map, and referenced by orientation-dependent color variables. During rendering, per-pixel vector orientations are mapped to color variables through a pair of angular coordinates, and pixel color values are provided by a corresponding entry in the color map.